package com.framwork.core.api.addressbook.user.input;

import com.alibaba.fastjson.JSONObject;
import com.framwork.core.base.AbstractAPIInput;
import com.framwork.core.base.em.RequestMappering;
import okhttp3.FormBody;
import okhttp3.RequestBody;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author ：james.liu
 * @date ：Created in 2022/3/4 14:55
 * @description：获取部门直属用户列表
 * @version: 1.0
 */
public class OpenApisContactV3UsersFindByDepartmentInput extends AbstractAPIInput {

    /**
     * 用户 ID 类型
     */
    private String userIdType = "open_id";
    /**
     * 此次调用中使用的部门ID的类型
     */
    private String departmentIdType;
    /**
     * 填写该字段表示获取该部门下用户，必填。根部门的部门ID为0。
     */
    private String departmentId = "0";
    /**
     * 分页大小
     */
    private Integer pageSize = 10;
    /**
     * 分页标记，第一次请求不填，表示从头开始遍历；分页查询结果还有更多项时会同时返回新的 page_token，下次遍历可采用该 page_token 获取查询结果
     */
    private Integer pageToken;

    public String getUserIdType() {
        return userIdType;
    }

    public void setUserIdType(String userIdType) {
        this.userIdType = userIdType;
    }

    public String getDepartmentIdType() {
        return departmentIdType;
    }

    public void setDepartmentIdType(String departmentIdType) {
        this.departmentIdType = departmentIdType;
    }

    public String getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(String departmentId) {
        this.departmentId = departmentId;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageToken() {
        return pageToken;
    }

    public void setPageToken(Integer pageToken) {
        this.pageToken = pageToken;
    }

    public final RequestBody toRequestBody() {
        RequestBody r = null;
        final FormBody.Builder builder = new FormBody.Builder();
        if (StringUtils.isNotBlank(this.getUserIdType())) {
            builder.add("user_id_type", this.getUserIdType());
        }
        if (StringUtils.isNotBlank(this.getDepartmentIdType())) {
            builder.add("department_id_type", this.getDepartmentIdType());
        }

        if (StringUtils.isNotBlank(this.getDepartmentId())) {
            builder.add("department_id", this.getDepartmentId());
        }
        if (Objects.nonNull(getPageSize())) {
            builder.add("page_size", String.valueOf(this.getPageSize()));
        }
        builder.add("page_token", (Objects.nonNull(this.getPageToken())) ? String.valueOf(this.getPageToken()) : "");
        return builder.build();
    }

    public final String toBody(OpenApisContactV3UsersFindByDepartmentInput input) {
        JSONObject r = new JSONObject();
        if (StringUtils.isNotBlank(input.getUserIdType())) {
            r.put("user_id_type", input.getUserIdType());
        }
        if (StringUtils.isNotBlank(input.getDepartmentIdType())) {
            r.put("department_id_type", input.getDepartmentIdType());
        }

        if (StringUtils.isNotBlank(input.getDepartmentId())) {
            r.put("department_id", input.getDepartmentId());
        }
        if (Objects.nonNull(getPageSize())) {
            r.put("page_size", String.valueOf(input.getPageSize()));
        }
        r.put("page_token", (Objects.nonNull(input.getPageToken())) ? String.valueOf(input.getPageToken()) : "");
        return r.toJSONString();

    }

    public final void eventCmd() {
        this.setCmdId(RequestMappering.open_apis_contact_v3_users_find_by_department.getMapperName());
    }

}
